package com.party.core.service.enterpriseservice.impl;

import com.google.common.base.Strings;
import com.party.common.paging.Page;
import com.party.core.dao.read.enterpriseservice.EpCategoryReadDao;
import com.party.core.dao.write.enterpriseservice.EpCategoryWriteDao;
import com.party.core.model.BaseModel;
import com.party.core.model.city.City;
import com.party.core.model.enterpriseservice.EpCategory;
import com.party.core.service.enterpriseservice.IEpCategoryService;
import com.sun.istack.NotNull;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Set;

/**
 * @program: party
 * @description: 服务类型service实现
 * @author: Hua Qunhao
 * @create: 2019-01-08 16:02
 */
@Service("EpCategoryService")
public class EpCategoryService implements IEpCategoryService {

    @Autowired
    private EpCategoryReadDao epCategoryReadDao;

    @Autowired
    private EpCategoryWriteDao epCategoryWriteDao;

    @Override
    public String insert(EpCategory epCategory) {
        BaseModel.preInsert(epCategory);
        boolean result = epCategoryWriteDao.insert(epCategory);
        if (result) {
            return epCategory.getId();
        }
        return null;
    }

    @Override
    public boolean update(EpCategory epCategory) {
        epCategory.setUpdateDate(new Date());
        return epCategoryWriteDao.update(epCategory);
    }

    @Override
    public boolean deleteLogic(@NotNull String id) {
        if (Strings.isNullOrEmpty(id)){
            return false;
        }
        return epCategoryWriteDao.deleteLogic(id);
    }

    @Override
    public boolean delete(@NotNull String id) {
        if (Strings.isNullOrEmpty(id)){
            return false;
        }
        return epCategoryWriteDao.delete(id);
    }

    @Override
    public boolean batchDeleteLogic(Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)){
            return false;
        }
        return epCategoryWriteDao.batchDeleteLogic(ids);
    }

    @Override
    public boolean batchDelete(Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)){
            return false;
        }
        return epCategoryWriteDao.batchDelete(ids);
    }

    @Override
    public EpCategory get(String id) {
        return epCategoryReadDao.get(id);
    }

    @Override
    public List<EpCategory> listPage(EpCategory epCategory, Page page) {
        return epCategoryReadDao.listPage(epCategory,page);
    }

    @Override
    public List<EpCategory> list(EpCategory epCategory) {
        return epCategoryReadDao.listPage(epCategory,null);
    }

    @Override
    public List<EpCategory> batchList(Set<String> ids, EpCategory epCategory, Page page) {
        if (CollectionUtils.isEmpty(ids)){
            return Collections.EMPTY_LIST;
        }
        return epCategoryReadDao.batchList(ids, new HashedMap(), page);
    }

    @Override
    public EpCategory findEpCategoryByName(String name) {
        return epCategoryReadDao.findEpCategoryByName(name);
    }

    @Override
    public List<EpCategory> queryEpCategoryByCity(City city) {
        return epCategoryReadDao.queryEpCategoryByCity(city);
    }
}
